package com.paishen.peiniwan.module.set;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.TextView;

import com.paishen.common.util.BaseUtil;
import com.paishen.peiniwan.BaseActivity;
import com.paishen.peiniwan.R;
import com.paishen.common.widget.TitleLayout;

import cn.jpush.android.api.JPushInterface;

public class SetNotificationActivity extends BaseActivity {
    private TextView txState;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_notification);

        TitleLayout layTitle = (TitleLayout) findViewById(R.id.lay_title);
        layTitle.pushContent(makeBackView(), getString(R.string.set_notification), null, false);

        txState = (TextView) findViewById(R.id.tx_state);

        findViewById(R.id.lay_state).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri packageURI = Uri.parse("package:" + getPackageName());
                Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
                startActivity(intent);
            }
        });

        JPushInterface.requestPermission(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        // 检测是否包含通知权限
        int r1 = BaseUtil.checkOp(11); // AppOpsManager.OP_POST_NOTIFICATION
        txState.setVisibility((r1 != -2) ? View.VISIBLE : View.GONE);
        txState.setText(r1 == 0 ? R.string.set_notification_switch_on : R.string.set_notification_switch_off);
    }
}
